#include "MessageItem.h"

MessageItem::MessageItem(const Message &message, QWidget *parent)
    : QWidget(parent), m_messageLabel(new QLabel(message.text(), this))
{
    layout = new QHBoxLayout(this);

    if (message.type() == Message::Received)
    {
        layout->addWidget(m_messageLabel, 0, Qt::AlignLeft);
    }
    else if (message.type() == Message::Sent)
    {
        layout->addWidget(m_messageLabel, 0, Qt::AlignRight);
    }

    setLayout(layout);
}

MessageItem::~MessageItem()
{
    m_messageLabel->deleteLater();
    layout->deleteLater();
}